<HTML><HEAD> <!-- --------- Graphlets --------- --> <SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers /* THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com Copyright (c)2000 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. */ //------------------RANDOM NUMBERS---------------------------- var js_mult1=3141 var js_mult2=5821 var js_m1=100000000 var js_m2=10000 var js_iseed=0 var js_iseed1=0 var js_iseed2=0 // Return a Random Integer between 0 and N-1 function random(n) { if (js_iseed == 0) { now = new Date() js_iseed = now.getHours() + now.getMinutes() * 60 + now.getSeconds() * 3600 } js_iseed1 = js_iseed / js_m2 js_iseed2 = js_iseed % js_m2 var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) * js_m2 + (js_iseed2 * js_mult2)) % js_m1 js_iseed = (tmp + 1) % js_m1 return (Math.floor((js_iseed/js_m1) * n)) } <!-- done hiding --></SCRIPT></HEAD> <BODY bgcolor="ffffff" link="0000ff" vlink="770077"> <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/SPICE.JPG" WIDTH=37 HEIGHT=72 ALIGN = LEFT>The Picture Game</H1></FONT> <BLOCKQUOTE> <FONT COLOR="770000"> Generating A Random Picture...(It may take a few seconds)<p> </FONT> <CENTER><SCRIPT> var color="BLACK" for (var tmpj = 0; tmpj < 12; tmpj++) { for (var tmpi = 0; tmpi < 12; tmpi++) { color = (random(2) == 1) ? "WHITE" : "BLACK" document.write("<img src=\"../GRAFX/"+color+".GIF\""+ "HEIGHT= 16 WIDTH=16>") } document.write("<br>") } </SCRIPT> <BR><BR> <FORM> <INPUT TYPE='BUTTON' VALUE='Show Another Random Picture' onClick="parent.JCcontent.history.go(0)"> </FORM> </CENTER> </BLOCKQUOTE> <br><br> <FONT COLOR="007777"><H2>Discussion</H2></FONT> <FONT SIZE=4> The <b>JavaScript Cookbook</b> Picture Generator builds pictures out of small black and white icons laid out in sequence. This script sets the color variable to "BLACK" initially. During the script, it randomly toggles back and forth. A carriage return follows each row using the break-line directive. <PRE><FONT COLOR="770000"> <SCRIPT> var color="BLACK" for (var tmpj = 0; tmpj < 12; tmpj++) { for (var tmpi = 0; tmpi < 12; tmpi++) { color = (random(2) == 1) ? "WHITE" : "BLACK" document.write(">img src=\"../GRAFX/"+color+".GIF\""+ "HEIGHT= 16 WIDTH=16>") } document.write("<br>") } </SCRIPT> </PRE></FONT> </FONT> <h5>Copyright ©1996 by Charles River Media, All Rights Reserved</h5> </BODY> </HTML>